﻿@model List<Affiliation>
@{
    ViewData["Title"] = "Affiliations";
}

<h2 class="mt-2">@ViewData["Title"]</h2>

<div class="table-wrapper">
    <table class="data-table table table-sm table-striped" style="width:auto">
        <thead>
            <tr role="row">
                <th scope="col" class="sortable searchable">ID</th>
                <th scope="col" class="sortable searchable">shortname</th>
                <th scope="col" class="sortable searchable">name</th>
                <th scope="col" class="sortable searchable">country</th>
                <th scope="col" class="sortable searchable">mail suffix</th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var aff in Model)
            {
                <tr asp-action="Detail" asp-route-affid="@aff.Id" role="row" data-target="gotoUrl">
                    <td use-a>@aff.Id</td>
                    <td use-a>@aff.Abbreviation</td>
                    <td use-a>@aff.Name</td>
                    <td use-a>@(aff.CountryCode ?? "(none)")</td>
                    <td use-a>@(aff.EmailSuffix ?? "(none)")</td>
                    <td><a asp-action="Edit" asp-route-affid="@aff.Id" title="edit this affiliation"><i class="fas fa-edit"></i></a></td>
                    <td><a asp-action="Delete" asp-route-affid="@aff.Id" data-toggle="ajaxWindow" title="delete this affiliation"><i class="fas fa-trash-alt"></i></a></td>
                </tr>
            }
        </tbody>
    </table>
</div>

<script>
    $().ready(function () {
        $('.data-table').DataTable({
            "paging": false,
            "searching": true,
            "ordering": true,
            "order": [[1, 'asc']],
            "info": false,
            "autoWidth": true,
            "language": {
                "searchPlaceholder": "filter table",
                "search": "_INPUT_",
            },
            'aoColumnDefs': [
                { aTargets: ['sortable'], bSortable: true },
                { aTargets: ['searchable'], bSearchable: true },
                { aTargets: ['_all'], bSortable: false, bSearchable: false }
            ],
        });
    });
</script>

<p>
    <a asp-action="Add" class="btn btn-primary" title="Add new affiliation"><i class="fas fa-plus"></i>&nbsp;Add new affiliation</a>
</p>
